<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-flash.min.css">
  <script src="/lib/pace/pace.min.js"></script>


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://kechenhh.gitee.io').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="组件通信—-父传子（props)123456789101112131415161718192021222324252627282930313233&lt;div id&#x3D;&quot;app&quot;&gt;       &lt;!--2.绑定--&gt;	&lt;cpn :cmovies&#x3D;&#39;movies&#39;&gt;&lt;&#x2F;cpn&gt;&lt;&#x2F;div&gt;	&lt;template id&#x3D;&quot;cpn&quot;&gt;	&amp;l">
<meta property="og:type" content="article">
<meta property="og:title" content="父子组件">
<meta property="og:url" content="https://kechenhh.gitee.io/%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6.html">
<meta property="og:site_name" content="我的博客">
<meta property="og:description" content="组件通信—-父传子（props)123456789101112131415161718192021222324252627282930313233&lt;div id&#x3D;&quot;app&quot;&gt;       &lt;!--2.绑定--&gt;	&lt;cpn :cmovies&#x3D;&#39;movies&#39;&gt;&lt;&#x2F;cpn&gt;&lt;&#x2F;div&gt;	&lt;template id&#x3D;&quot;cpn&quot;&gt;	&amp;l">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-01-14T02:30:15.000Z">
<meta property="article:modified_time" content="2020-12-14T09:47:00.268Z">
<meta property="article:author" content="kechenhh">
<meta property="article:tag" content="vue">
<meta property="article:tag" content="父子组件">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://kechenhh.gitee.io/%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>父子组件 | 我的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle"> my blog</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://kechenhh.gitee.io/%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="kechenhh">
      <meta itemprop="description" content="学习笔记">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          父子组件
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-01-14 10:30:15" itemprop="dateCreated datePublished" datetime="2020-01-14T10:30:15+08:00">2020-01-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-12-14 17:47:00" itemprop="dateModified" datetime="2020-12-14T17:47:00+08:00">2020-12-14</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/" itemprop="url" rel="index">
                    <span itemprop="name">Vue</span>
                  </a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/%E7%BB%84%E4%BB%B6%E5%8C%96%E5%BC%80%E5%8F%91/" itemprop="url" rel="index">
                    <span itemprop="name">组件化开发</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="组件通信—-父传子（props"><a href="#组件通信—-父传子（props" class="headerlink" title="组件通信—-父传子（props)"></a>组件通信—-父传子（props)</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">       <span class="comment">&lt;!--2.绑定--&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span> <span class="attr">:cmovies</span>=<span class="string">'movies'</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">li</span> <span class="attr">v-for</span>=<span class="string">"item in cmovies"</span>&gt;</span>&#123;&#123;item&#125;&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">	<span class="comment">//父传子：props==&gt;properties 属性</span></span></span><br><span class="line"><span class="actionscript">	<span class="comment">// 子组件</span></span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">'#cpn'</span>,</span></span><br><span class="line"><span class="actionscript">		<span class="comment">//1.定义</span></span></span><br><span class="line"><span class="actionscript">		props:[<span class="string">'cmovies'</span>],</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="actionscript">	<span class="comment">// 父组件(Vue实例)</span></span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span>,</span></span><br><span class="line"><span class="actionscript">			movies:[<span class="string">'海王'</span>,<span class="string">'超人'</span>]</span></span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<a id="more"></a>

<h3 id="props中的驼峰标识"><a href="#props中的驼峰标识" class="headerlink" title="props中的驼峰标识"></a>props中的驼峰标识</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 不支持驼峰标识  cInfo转换为c-info,childMyMessage转换为child-my-message--&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span> <span class="attr">:c-info</span>=<span class="string">"info"</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 模板有多个标签时，必须包含根标签(例：div) --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>&#123;&#123;cInfo&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">'#cpn'</span>,</span></span><br><span class="line">		props:&#123;</span><br><span class="line"><span class="actionscript">			<span class="comment">//驼峰标识</span></span></span><br><span class="line">			cInfo:&#123;</span><br><span class="line"><span class="javascript">				type: <span class="built_in">Object</span>,</span></span><br><span class="line"><span class="actionscript">				<span class="keyword">default</span>()&#123;</span></span><br><span class="line"><span class="actionscript">					<span class="keyword">return</span>&#123;name:<span class="string">'某人'</span>&#125;</span></span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span>,</span></span><br><span class="line">			info:&#123;</span><br><span class="line"><span class="actionscript">				name:<span class="string">'jack'</span>,</span></span><br><span class="line">				age:18</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="组件通信—子传父（自定义事件名称）"><a href="#组件通信—子传父（自定义事件名称）" class="headerlink" title="组件通信—子传父（自定义事件名称）"></a>组件通信—子传父（自定义事件名称）</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 2.监听事件 --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span> @<span class="attr">item-click</span>=<span class="string">"cpnClick"</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">v-for</span>=<span class="string">"item in categories"</span> @<span class="attr">click</span>=<span class="string">"btnClick(item)"</span>&gt;</span></span><br><span class="line">			&#123;&#123;item.name&#125;&#125;</span><br><span class="line">		<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">'#cpn'</span>,</span></span><br><span class="line">		data()&#123;</span><br><span class="line"><span class="actionscript">			<span class="keyword">return</span>&#123;</span></span><br><span class="line">				categories:[</span><br><span class="line"><span class="actionscript">					&#123;id:<span class="string">'aaa'</span>,name:<span class="string">'热门推荐'</span>&#125;,</span></span><br><span class="line"><span class="actionscript">					&#123;id:<span class="string">'bbb'</span>,name:<span class="string">'手机数码'</span>&#125;,</span></span><br><span class="line"><span class="actionscript">					&#123;id:<span class="string">'ccc'</span>,name:<span class="string">'家用家电'</span>&#125;,</span></span><br><span class="line"><span class="actionscript">					&#123;id:<span class="string">'ddd'</span>,name:<span class="string">'电脑办公'</span>&#125;,</span></span><br><span class="line">				]</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		methods:&#123;</span><br><span class="line">			btnClick(item)&#123;</span><br><span class="line"><span class="actionscript">				<span class="comment">//1.发射事件	this.$emit('自定义事件名称',item)</span></span></span><br><span class="line"><span class="actionscript">				<span class="keyword">this</span>.$emit(<span class="string">'item-click'</span>,item)</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span>,</span></span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;,</span><br><span class="line">		methods:&#123;</span><br><span class="line">			cpnClick(item)&#123;</span><br><span class="line"><span class="javascript">				<span class="built_in">console</span>.log(item.name)</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="父子组件通信-结合双向绑定案例"><a href="#父子组件通信-结合双向绑定案例" class="headerlink" title="父子组件通信-结合双向绑定案例"></a>父子组件通信-结合双向绑定案例</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span> <span class="attr">:number1</span>=<span class="string">"num1"</span></span></span><br><span class="line"><span class="tag">			<span class="attr">:number2</span>=<span class="string">"num2"</span></span></span><br><span class="line"><span class="tag">			@<span class="attr">number1change</span>=<span class="string">"number1change"</span></span></span><br><span class="line"><span class="tag">			@<span class="attr">number2change</span>=<span class="string">"number2change"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>props:&#123;&#123;number1&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>data:&#123;&#123;dnumber1&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- &lt;input type="text" v-model="dnumber1"&gt; --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">:value</span>=<span class="string">"dnumber1"</span> @<span class="attr">input</span>=<span class="string">"num1Input"</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>props:&#123;&#123;number2&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>data:&#123;&#123;dnumber2&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- &lt;input type="text" v-model="dnumber2"&gt; --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">:value</span>=<span class="string">"dnumber2"</span> @<span class="attr">input</span>=<span class="string">"num2Input"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">'#cpn'</span>,</span></span><br><span class="line">		props:&#123;</span><br><span class="line"><span class="javascript">			number1:<span class="built_in">Number</span>,</span></span><br><span class="line"><span class="javascript">			number2:<span class="built_in">Number</span></span></span><br><span class="line">		&#125;,</span><br><span class="line">		data()&#123;</span><br><span class="line"><span class="actionscript">			<span class="keyword">return</span>&#123;</span></span><br><span class="line"><span class="actionscript">				dnumber1:<span class="keyword">this</span>.number1,</span></span><br><span class="line"><span class="actionscript">				dnumber2:<span class="keyword">this</span>.number2,</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		methods:&#123;</span><br><span class="line">			num1Input(event)&#123;</span><br><span class="line"><span class="actionscript">				<span class="comment">//1.将input中的value赋值到dnumber中</span></span></span><br><span class="line"><span class="actionscript">				<span class="keyword">this</span>.dnumber1 = event.target.value</span></span><br><span class="line"><span class="actionscript">				<span class="comment">//2.为了让父组件可以修改值，发出一个事件</span></span></span><br><span class="line"><span class="actionscript">				<span class="keyword">this</span>.$emit(<span class="string">'number1change'</span>,<span class="keyword">this</span>.dnumber1)</span></span><br><span class="line">			&#125;,</span><br><span class="line">			num2Input(event)&#123;</span><br><span class="line"><span class="actionscript">				<span class="keyword">this</span>.dnumber2 = event.target.value</span></span><br><span class="line"><span class="actionscript">				<span class="keyword">this</span>.$emit(<span class="string">'number2change'</span>,<span class="keyword">this</span>.dnumber2)</span></span><br><span class="line">			&#125;,</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span>,</span></span><br><span class="line">			num1:0,</span><br><span class="line">			num2:1</span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;,</span><br><span class="line">		methods:&#123;</span><br><span class="line">			number1change(value)&#123;</span><br><span class="line"><span class="javascript">				<span class="keyword">this</span>.num1= <span class="built_in">parseFloat</span>(value)</span></span><br><span class="line">			&#125;,</span><br><span class="line">			number2change(value)&#123;</span><br><span class="line"><span class="javascript">				<span class="keyword">this</span>.num2= <span class="built_in">parseFloat</span>(value)</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="组件访问–父访问子-children或-refs"><a href="#组件访问–父访问子-children或-refs" class="headerlink" title="组件访问–父访问子$children或$refs"></a>组件访问–父访问子$children或$refs</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 加上ref --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span> <span class="attr">ref</span>=<span class="string">"aaa"</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> @<span class="attr">click</span>=<span class="string">"btnClick"</span>&gt;</span>按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		我是子组件</span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">"#cpn"</span>,</span></span><br><span class="line">		methods:&#123;</span><br><span class="line">			showMessage()&#123;</span><br><span class="line"><span class="javascript">				<span class="built_in">console</span>.log(<span class="string">'这是子组件showMessage'</span>);</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		data()&#123;</span><br><span class="line"><span class="actionscript">			<span class="keyword">return</span>&#123;</span></span><br><span class="line"><span class="actionscript">				name:<span class="string">'子组件name'</span></span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span></span></span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;,</span><br><span class="line">		methods:&#123;</span><br><span class="line">			btnClick()&#123;</span><br><span class="line"><span class="actionscript">				<span class="comment">// 1.$children(使用较少)</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// console.log(this.$children);</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">//调用子组件的方法</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// this.$children[0].showMessage();</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">//调用子组件的属性</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// console.log(this.$children[0].name);</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">//遍历</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// for(let c of this.$children)&#123;</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// 	console.log(c.name);</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// 	c.showMessage()</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">// &#125;</span></span></span><br><span class="line">				</span><br><span class="line"><span class="actionscript">				<span class="comment">// 2.$refs</span></span></span><br><span class="line"><span class="javascript">				<span class="built_in">console</span>.log(<span class="keyword">this</span>.$refs.aaa.name)</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="组件访问–子访问父-parent或-root"><a href="#组件访问–子访问父-parent或-root" class="headerlink" title="组件访问–子访问父$parent或$root"></a>组件访问–子访问父$parent或$root</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">cpn</span>&gt;</span><span class="tag">&lt;/<span class="name">cpn</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"cpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		我是cpn组件</span><br><span class="line">		<span class="tag">&lt;<span class="name">ccpn</span>&gt;</span><span class="tag">&lt;/<span class="name">ccpn</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">"ccpn"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">h2</span>&gt;</span>我是子组件<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> @<span class="attr">click</span>=<span class="string">"btnClick"</span>&gt;</span>按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../vue.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">	<span class="comment">//子组件</span></span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> ccpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">"#ccpn"</span>,</span></span><br><span class="line">		methods:&#123;</span><br><span class="line">			btnClick()&#123;</span><br><span class="line"><span class="actionscript">				<span class="comment">//1.访问父组件$parent(使用较少)</span></span></span><br><span class="line"><span class="javascript">				<span class="built_in">console</span>.log(<span class="keyword">this</span>.$parent.name);</span></span><br><span class="line"><span class="actionscript">				<span class="comment">//2.访问根组件$root(使用较少)--访问Vue实例</span></span></span><br><span class="line"><span class="javascript">				<span class="built_in">console</span>.log(<span class="keyword">this</span>.$root.message);</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">	&#125;</span><br><span class="line"><span class="actionscript">	<span class="comment">//父组件</span></span></span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> cpn = &#123;</span></span><br><span class="line"><span class="actionscript">		template:<span class="string">"#cpn"</span>,</span></span><br><span class="line">		components:&#123;</span><br><span class="line">			ccpn</span><br><span class="line">		&#125;,</span><br><span class="line">		data()&#123;</span><br><span class="line"><span class="actionscript">			<span class="keyword">return</span>&#123;</span></span><br><span class="line"><span class="actionscript">				name:<span class="string">'cpn组件的name'</span></span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line"><span class="actionscript">	<span class="keyword">const</span> app = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">		el:<span class="string">'#app'</span>,</span></span><br><span class="line">		data:&#123;</span><br><span class="line"><span class="actionscript">			message:<span class="string">'你好Vue'</span></span></span><br><span class="line">		&#125;,</span><br><span class="line">		components:&#123;</span><br><span class="line">			cpn</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/vue/" rel="tag"># vue</a>
              <a href="/tags/%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6/" rel="tag"># 父子组件</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/%E6%B5%8B%E8%AF%95.html" rel="prev" title="测试">
      <i class="fa fa-chevron-left"></i> 测试
    </a></div>
      <div class="post-nav-item">
    <a href="/HTML5.html" rel="next" title="HTML5">
      HTML5 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#组件通信—-父传子（props"><span class="nav-number">1.</span> <span class="nav-text">组件通信—-父传子（props)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#props中的驼峰标识"><span class="nav-number">2.</span> <span class="nav-text">props中的驼峰标识</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#组件通信—子传父（自定义事件名称）"><span class="nav-number">3.</span> <span class="nav-text">组件通信—子传父（自定义事件名称）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#父子组件通信-结合双向绑定案例"><span class="nav-number">4.</span> <span class="nav-text">父子组件通信-结合双向绑定案例</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#组件访问–父访问子-children或-refs"><span class="nav-number">5.</span> <span class="nav-text">组件访问–父访问子$children或$refs</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#组件访问–子访问父-parent或-root"><span class="nav-number">6.</span> <span class="nav-text">组件访问–子访问父$parent或$root</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="kechenhh"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">kechenhh</p>
  <div class="site-description" itemprop="description">学习笔记</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/kechenhh" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;kechenhh" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">kechenhh</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.0
  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
